<?php

class Admin_CatalogController extends My_Controller_ActionAdmin {

    public function indexAction() {
        $daoCatalog = new Application_Model_DAO_Catalog();
        $list = $daoCatalog->getFullEntries();
        $this->view->list = $this->createPaginator($list);
    }

    public function deactivateAction() {
        $code = $this->_getParam('id');
        $form = new Admin_Form_Confirmation();

        if (!$this->_request->isPost() || !$form->isValid($_POST)) {
            if (!$this->_request->isPost()) {
                $form->getElement('id')->setValue($code);
            }
            $this->view->form = $form;
            $this->renderForm();
            return;
        }
        if (!$form->isConfirmed()) {
            return;
        }
        $code = $form->getElement('id')->getValue();
        $daoOffer = new Application_Model_DAO_Catalog();
        $daoOffer->deactivate($code, 'code');

        $this->addSuccess($this->translate('XXX_ADMIN_CATALOG_DEACTIVATE_SUCCESS'));
        $url = $this->url(array('controller' => 'catalog', 'action' => 'index'));
        $this->_redirect($url);
    }
    
    public function activateAction() {
        $code = $this->_getParam('id');
        $form = new Admin_Form_Confirmation();

        if (!$this->_request->isPost() || !$form->isValid($_POST)) {
            if (!$this->_request->isPost()) {
                $form->getElement('id')->setValue($code);
            }
            $this->view->form = $form;
            $this->renderForm();
            return;
        }
        if (!$form->isConfirmed()) {
            return;
        }
        $code = $form->getElement('id')->getValue();
        $daoOffer = new Application_Model_DAO_Catalog();
        $daoOffer->activate($code, 'code');

        $this->addSuccess($this->translate('XXX_ADMIN_CATALOG_ACTIVATE_SUCCESS'));
        $url = $this->url(array('controller' => 'catalog', 'action' => 'index'));
        $this->_redirect($url);
    }

}

